package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MatIn;
import com.woniuxy.mesboot.service.MatinService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/matin")
public class MatinController {
    @Resource
    private MatinService matinService;

    @GetMapping
    public Result queryAll() {
        List<MatIn> i = matinService.selectAll();
        return Result.ok().data("list", i);
    }

    @PostMapping
    public Result insert(@RequestBody MatIn matIn) {
        int i = matinService.insertSelective(matIn);
        if (i > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }

    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MatIn matIn = matinService.selectByPrimaryKey(id);
        return Result.ok().data("item", matIn);
    }

    @DeleteMapping("{id}")

    public Result delete(@PathVariable Long id) {
        int i = matinService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");

        } else {
            return Result.error("删除失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody MatIn matIn) {
        int i = matinService.updateByPrimaryKey(matIn);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }

    }


}
